/**
 * @param {string} path
 * @return {string}
 * 输入：path = "/a/./b/../../c/"
输出："/c"
 */
var simplifyPath = function (path) {
  const formatPath = path => {
    if (path === '/') {
      return path
    }
    let pathArr = path.split('//')
    if (pathArr.length === 1) {
      return path
    }
    return formatPath(pathArr.join('/'))
  }
  const pathRes = []
  let Fpath = formatPath(path)
  if (Fpath.charAt(Fpath.length - 1) === '/') {
    Fpath = Fpath.slice(0, Fpath.length - 1)
  }
  const pathArr = Fpath.split('')
  let i = 0
  while (i < pathArr.length) {
    i++
    if (pathArr[i - 1] === '/') {
      let str = '/'
      while (i < Fpath.length && pathArr[i] !== '/') {
        str += pathArr[i]
        i++
      }
      if (str === '/.') {
      } else if (str === '/..') {
        pathRes.length > 0 ? pathRes.pop() : pathRes.push('/')
      } else {
        pathRes.push(str)
      }
    }
  }
  return pathRes.length === 0 ? '/' : formatPath(pathRes.join(''))
}
console.log(simplifyPath('/a/./b///../c/../././../d/..//../e/./f/./g/././//.//h///././/..///'))
